{% extends 'base.html' %}

{% block title %}注册 - 电影推荐系统{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <h3 class="mb-0">创建新账号</h3>
            </div>
            <div class="card-body">
                {% if messages %}
                <div class="messages mb-3">
                    {% for message in messages %}
                    <div class="alert alert-{{ message.tags }}">
                        {{ message }}
                    </div>
                    {% endfor %}
                </div>
                {% endif %}
                
                {% if form.non_field_errors %}
                <div class="alert alert-danger">
                    {% for error in form.non_field_errors %}
                    {{ error }}
                    {% endfor %}
                </div>
                {% endif %}
                
                <form method="post" action="{% url 'register' %}">
                    {% csrf_token %}
                    
                    <div class="mb-3">
                        <label for="id_username" class="form-label">用户名</label>
                        <input type="text" name="username" class="form-control {% if form.username.errors %}is-invalid{% endif %}" id="id_username" value="{{ form.username.value|default:'' }}" required>
                        {% if form.username.errors %}
                        <div class="invalid-feedback">
                            {% for error in form.username.errors %}
                            {{ error }}
                            {% endfor %}
                        </div>
                        {% endif %}
                        <div class="form-text">必填。150个字符或者更少。包含字母，数字和仅有的@/./+/-/_符号。</div>
                    </div>
                    
                    <div class="mb-3">
                        <label for="id_email" class="form-label">电子邮件</label>
                        <input type="email" name="email" class="form-control {% if form.email.errors %}is-invalid{% endif %}" id="id_email" value="{{ form.email.value|default:'' }}" required>
                        {% if form.email.errors %}
                        <div class="invalid-feedback">
                            {% for error in form.email.errors %}
                            {{ error }}
                            {% endfor %}
                        </div>
                        {% endif %}
                    </div>
                    
                    <div class="mb-3">
                        <label for="id_password1" class="form-label">密码</label>
                        <input type="password" name="password1" class="form-control {% if form.password1.errors %}is-invalid{% endif %}" id="id_password1" required>
                        {% if form.password1.errors %}
                        <div class="invalid-feedback">
                            {% for error in form.password1.errors %}
                            {{ error }}
                            {% endfor %}
                        </div>
                        {% endif %}
                        <div class="form-text">
                            <ul>
                                <li>你的密码不能与你的其他个人信息太相似。</li>
                                <li>你的密码必须包含至少 8 个字符。</li>
                                <li>你的密码不能是大家都爱用的常见密码。</li>
                                <li>你的密码不能全部为数字。</li>
                            </ul>
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <label for="id_password2" class="form-label">确认密码</label>
                        <input type="password" name="password2" class="form-control {% if form.password2.errors %}is-invalid{% endif %}" id="id_password2" required>
                        {% if form.password2.errors %}
                        <div class="invalid-feedback">
                            {% for error in form.password2.errors %}
                            {{ error }}
                            {% endfor %}
                        </div>
                        {% endif %}
                        <div class="form-text">为了校验，请输入与上面相同的密码。</div>
                    </div>
                    
                    <button type="submit" class="btn btn-primary">注册</button>
                </form>
                
                <div class="mt-3">
                    <p>已有账号？<a href="{% url 'login' %}">登录</a></p>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %} 